package baseTest;

public class reverseList {
    public static void main(String[] args) {
        ListNode node1 = new ListNode(1);

        ListNode node = new ListNode(0);
        node1.next = node;

        for (int i = 0; i < 10 ; i++) {
            node.next = new ListNode(i);
            node = node.next;
        }

        System.out.println(process(node1).val);
    }

    public static ListNode process(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode pre = null;
        ListNode next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }
}
